import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

export default new Router({
  // 如果不配置 mode，就会使用默认的 hash 模式，该模式下会将路径格式化为 #! 开头.添加 mode: 'history' 之后将使用 HTML5 history 模式，该模式下没有 # 前缀，而且可以使用 pushState 和 replaceState 来管理记录。
  mode: 'history',
  // 通过懒加载就不会一次性把所有组件都加载进来，而是当你访问到那个组件的时候才会加载那一个。对于组件比较多的应用会提高首次加载速度。
  routes: [
    {path: '/', redirect: '/login'},
    {path: '/login', component:resolve => require(['../views/Login'], resolve)},
    {
      path: '/', component: resolve => require(['../components/Home'], resolve),
      children: [
        {path: 'default', component: resolve => require(['../components/default'], resolve),meta:{title:'首页'}},
        {path: 'forbidden', component: resolve => require(['../views/Forbidden'], resolve),meta:{title:'禁止'}},
        {
          path: 'admin-password',
          component: resolve => require(['../views/ChangePassword'], resolve),
          meta: {keepAlive: true,title:'修改密码'}
        }
      ]
    },
    {path: '/unauthorized', component: resolve => require(['../views/Unauthorized'], resolve),meta:{title:'未授权'}},
    {path: '*', component: resolve => require(['../views/NotFound'], resolve)},

  ]
})
